namespace C4F.DevKit.Bluetooth
{
    namespace ServiceAndDeviceDiscovery
    {

        #region Using Directives
        using System;
        using System.Collections.Generic;
        using System.Text;
        using System.Runtime.Serialization;
        using C4F.DevKit.Bluetooth.ServiceAndDeviceDiscovery.Resources;
        #endregion

        /// <summary>
        /// A generic exception which will be raised when a 
        /// windows socket error has occurred
        /// </summary>
        [Serializable]
        public class WinsockException : Exception
        {
            #region Private Member
            /// <summary>
            /// Encapsulates the windows error.
            /// </summary>
            private WinsockError winsockErrorObject;
            #endregion

            #region Public Property
            /// <summary>
            /// Gets the error
            /// </summary>
            public WinsockError Error
            {
                get
                {
                    return winsockErrorObject;
                }
            }
            #endregion

            #region Constructor
           
            /// <summary>
            /// Initializes the Message property of the new instance to a 
            /// system-supplied message.
            /// </summary>
            /// <param name="winsockError">Represents the winsock error instance.</param>
            public WinsockException(WinsockError winsockError)
                : base()
            {
                winsockErrorObject = winsockError;
            }
            /// <summary>
            /// Initializes an object of this class and sets the Message property 
            /// to the specified error message.
            /// </summary>
            /// <param name="winsockError">Winsock error instance.</param>
            /// <param name="message">The message that describes the error.
            /// </param>
            public WinsockException(WinsockError winsockError, string message)
                : base(message)
            {
                winsockErrorObject = winsockError;
            }
            /// <summary>
            /// Initializes a new instance of the Exception class with a 
            /// specified error message and a reference 
            /// to the inner exception that is the cause of this exception.
            /// </summary>
            /// <param name="winsockError">Winsock error instance.</param>
            /// <param name="message">he message that describes the error.
            /// </param>
            /// <param name="innerException">The exception that is the cause of
            /// this exception.</param>
            public WinsockException(WinsockError winsockError, string message,
                                    Exception innerException)
                : base(message, innerException)
            {
                winsockErrorObject = winsockError;
            }
            /// <summary>
            /// Initializes a new instance of this class with serialized data.             
            /// </summary>
            /// <param name="info">The SerializationInfo that holds the serialized
            /// object data about the exception being thrown.</param>
            /// <param name="context">The StreamingContext that contains contextual
            /// information about the source or destination.</param>
            public WinsockException(SerializationInfo info, StreamingContext context)
                : base(info, context)
            {
                if (info != null)
                {
                    winsockErrorObject =
                        (WinsockError)info.GetValue
                                    (BluetoothHelperMessages.GetObjectDataFieldError,
                                     typeof(WinsockError));

                }
            }
            /// <summary>
            /// Overrides the GetObjectData method of the base class Exception
            /// </summary>
            /// <param name="info">The SerializationInfo that holds the serialized
            /// object data about the exception being thrown.</param>
            /// <param name="context">The StreamingContext that contains contextual
            /// information about the source or destination.</param>

            #endregion

            #region Public Function
            public override void GetObjectData(SerializationInfo info,
                                               StreamingContext context)
            {
                base.GetObjectData(info, context);

                if (info != null)
                {
                    info.AddValue
                        (BluetoothHelperMessages.GetObjectDataFieldError,
                         this.Error);
                }
            }
            #endregion

        }

    }
}